﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhDataAcess.orderLinqDAL;
using dhSystemBLL.orderData;
using baseSet;
using dhDataAcess.baseBLL;

namespace dhsystem.orderForm
{
    public partial class FrmorderDetailUpdateAdd : Form
    {
        public string retqty { get; set; }
        orderDetailUpdateBLL orderDetailupdate = new orderDetailUpdateBLL();
        orderDetailUpdateModel orderDetailupdaterow = new orderDetailUpdateModel();
        orderMasterBLL orderMaster = new orderMasterBLL();
        orderDetailBLL orderDetail = new orderDetailBLL();
        BindingSource BindingSourceorderDetailupdateAdd;
        string state;
        string orderDetailNo;
        string orderNo;
        string   qty;
        public FrmorderDetailUpdateAdd(BindingSource _bindingSourceorderDetailupdate, string _state,string _orderDetailNo,string _orderNo,string   _qty)
        {
            InitializeComponent();
            BindingSourceorderDetailupdateAdd = _bindingSourceorderDetailupdate;
            state = _state;
            orderDetailNo = _orderDetailNo;
            orderNo = _orderNo;
            qty =_qty ;
        }
        //打开窗口时绑定数据
        private void FrmorderDetailUpdateAdd_Load(object sender, EventArgs e)
        {
            
            textorderNo.Text = orderNo;
            textorderDetailNo.Text = orderDetailNo;
            textQtyO.Text = qty;
            textQtyN.Focus();
            //if (state == "编辑")
            //{

            //    textorderNo.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "orderNo");
            //    textorderDetailNo.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "orderDetailNo");
            //    textQtyO.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "QtyO");
            //    textQtyN.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "QtyN");
            //    textQtyMark.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "QtyMark");
            //    dateTimeupdateDate.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "updateDate");
            //    checklastUpdate.DataBindings.Add("checked", BindingSourceorderDetailupdateAdd, "lastUpdate");
            //    textmark.DataBindings.Add("text", BindingSourceorderDetailupdateAdd, "mark");
            
            //}
        }
        //保存按钮，插入或修改数据
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (state == "新增")
            {
                try
                {
                    DialogResult result = MessageBox.Show("是否新增订单数量变更表！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        
                        orderDetailupdaterow.orderNo = textorderNo.Text;
                        orderDetailupdaterow.orderDetailNo = textorderDetailNo.Text;
                        orderDetailupdaterow.QtyMark = textQtyMark.Text;
                        orderDetailupdaterow.QtyN =Convert .ToDecimal ( textQtyN.Text);
                        orderDetailupdaterow.QtyO =Convert .ToDecimal ( textQtyO.Text);
                        orderDetailupdaterow.updateDate = dateTimeupdateDate.Value;
                        orderDetailupdaterow.lastUpdate = checklastUpdate.Checked.ToString();
                        orderDetailupdaterow.mark = textmark.Text;
                        orderDetailupdaterow.updateUser = GlobalInfo.UserName;
                        orderDetailupdate .orderDetailUpdateInsert (orderDetailupdaterow );
                        bindingSourceorderDetailUpdate.DataSource = orderDetailupdate.getorderDetailUpdateAll();
                        if (basicSql.getintbyorderProduceList(orderDetailNo ) >= 1)
                        {
                            MessageBox.Show("该产品已做生产通知单，注意修改生产通知单数量");
                        }
                      //  MessageBox.Show("新增成功");
                        retqty = textQtyN.Text;
                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            if (state == "编辑")
            {
                try
                {
                    DialogResult result = MessageBox.Show("是否修改订单数量变更表！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        orderDetailupdaterow.orderNo = textorderNo.Text;
                        orderDetailupdaterow.orderDetailNo = textorderDetailNo.Text;
                        orderDetailupdaterow.QtyMark = textQtyMark.Text;
                        orderDetailupdaterow.QtyN = Convert.ToDecimal(textQtyN.Text);
                        orderDetailupdaterow.QtyO = Convert.ToDecimal(textQtyO.Text);
                        orderDetailupdaterow.updateDate = dateTimeupdateDate.Value;
                        orderDetailupdaterow.lastUpdate = checklastUpdate.Checked.ToString();
                        orderDetailupdaterow.mark = textmark.Text;
                        orderDetailupdaterow.updateUser = GlobalInfo.UserName;
                        orderDetailupdate.orderDetailUpdateUpdate (orderDetailupdaterow);
                        bindingSourceorderDetailUpdate.DataSource = orderDetailupdate.getorderDetailUpdateAll();
                        MessageBox.Show("修改成功");
                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
        //退出按钮
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
